// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import java.sql.SQLException;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.DisabledCommand;
import zombie.commands.RequiredRight;
import zombie.core.logger.LoggerManager;
import zombie.core.raknet.UdpConnection;
import zombie.network.GameServer;
import zombie.network.ServerWorldDatabase;

@DisabledCommand
@CommandName(
    name = "addalltowhitelist"
)
@CommandHelp(
    helpText = "UI_ServerOptionDesc_AddAllWhitelist"
)
@RequiredRight(
    requiredRights = 48
)
public class AddAllToWhiteListCommand extends CommandBase {
    public AddAllToWhiteListCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    @Override
    protected String Command() {
        StringBuilder stringBuilder = new StringBuilder("");

        for (int _int = 0; _int < GameServer.udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)GameServer.udpEngine.connections.get(_int);
            if (udpConnection.password != null && !udpConnection.password.equals("")) {
                LoggerManager.getLogger("admin")
                    .write(this.getExecutorUsername() + " created user " + udpConnection.username + " with password " + udpConnection.password);

                try {
                    stringBuilder.append(ServerWorldDatabase.instance.addUser(udpConnection.username, udpConnection.password)).append(" <LINE> ");
                } catch (SQLException sQLException) {
                    sQLException.printStackTrace();
                }
            } else {
                stringBuilder.append("User ").append(udpConnection.username).append(" doesn't have a password. <LINE> ");
            }
        }

        stringBuilder.append("Done.");
        return stringBuilder.toString();
    }
}
